import os
from PIL import Image, ImageDraw, ImageFont
from NoBad.settings.dev import FONT_DIR

# 检查字体文件是否存在
font_path = f"{FONT_DIR}/SourceHanSans-Normal.ttc"
print(f"字体路径: {font_path}")
if os.path.exists(font_path):
    print("字体文件存在")
else:
    print("字体文件不存在，请检查路径")

# 创建测试图像
img = Image.new('RGB', (800, 200), color=(255, 255, 255))
draw = ImageDraw.Draw(img)

try:
    # 尝试加载字体
    font = ImageFont.truetype(font_path, 32, encoding="utf-8")
    print("字体加载成功")
except Exception as e:
    print(f"字体加载失败: {e}")
    # 使用默认字体作为备选
    font = ImageFont.load_default()

# 测试绘制中文字符
test_text = "你好世界 测试中文"
try:
    draw.text((50, 50), test_text, font=font, fill=(0, 0, 0))
    img.save("font_test.png")
    print("中文文字绘制完成，已保存为 font_test.png")
except Exception as e:
    print(f"文字绘制失败: {e}")
